package com.heima.wemedia.controller.v1;

import com.heima.model.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/v1/material")
@Api(value = "阿里云图片controller",tags = "阿里云图片controller")
public class OssController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult upLoadPicture(@RequestBody MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }
    @ApiOperation(value = "查询素材")
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDTO wmMaterialDTO){
        return wmMaterialService.findList(wmMaterialDTO);
    }

    @ApiOperation(value = "删除素材")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id) {
        return wmMaterialService.delPicture(id);
    }

    @ApiOperation(value = "添加收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult addCollect(@PathVariable("id") Integer id) {
        return wmMaterialService.addCancelCollect(id,WemediaConstants.COLLECT_MATERIAL);
    }

    @ApiOperation(value = "取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectCollect(@PathVariable("id") Integer id) {
        return wmMaterialService.addCancelCollect(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

}
